<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>紫色鹭</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/zTreeStyle.css">

    <link rel="stylesheet" href="../css/style.css">

</head>
<body>
<div id="header_01_html">
    <iframe id="header_01" src="head_01.html" frameborder="0"></iframe>
</div>
<div id="head_search_html">
    <iframe id="head_search" src="head_search.html" frameborder="0"></iframe>
</div>
<div class="container store_product clearfix" v-cloak>
    <div class="store_tab">
        <a  mhref="store_info.html" class="store-info">基本信息</a>
        <a  mhref="store_banner.html" class="banner-admmin" v-show="storeId!=false?true:false">轮播管理</a>
        <a  class="active">商品管理</a>
        <a  mhref="store_manage.html" class="order-admin">订单管理</a>
        <a class="has_store store-enter">企业认证</a>
        <!--<a  mhref="store_evaluate.html" class="evaluate-admin">评价管理</a>-->
    </div>
    <div class="right">
        <a class="add_product cur-p" @click="goProadd">新增商品</a>
        <div class="list">
            <div class="title">
                <i class="icon_checkbox js-status" data-status=""></i>全部
                <i class="icon_checkbox js-status" data-status="0"></i>上架
                <i class="icon_checkbox js-status" data-status="1"></i>下架
            </div>
            <table>
                <tr v-for="item in list">
                    <td>
                        <div class="img">
                            <img v-for="(it,index) in item.picUrl" :src="imgBaseUrl + it" v-if="index == 0" alt="">
                        </div>
                    </td>
                    <td>
                        <div class="box">
                            <p class="mb10">{{item.name}}</p>
                            <p class="mb15 c_999">型号：{{item.origin}} &nbsp;&nbsp;   品牌：{{item.originName}}</p>
                            <!--<p class="c_999">成交量：20件</p>-->
                        </div>
                    </td>
                    <td class="price"><div>¥ {{item.price}}</div></td>
                    <td>
                        <div class="button" @click="toUp(item)" v-if="item.state == 1">上架</div>
                        <div class="button" @click="toDown(item)"  v-if="item.state == 0">下架</div>
                        <div class="button" @click="toEdit(item.id)">编辑</div>
                    </td>
                </tr>
            </table>
        </div>
        <div id="test1"></div>
    </div>
</div>
<div class="tabRight">
    <div class="first">
        <ul>
            <li><a target="_blank" class="icon_admin_white" title=""></a></li>
            <li>
                <a target="_blank" class="go-shopcard c-fff">
                    <i class="icon_shopcar_white"></i>
                    <p class="mt10">购<br>物<br>车</p>
                    <span class="car-num pos-Sty1">0</span>
                </a>
            </li>
            <li>
                <a target="_blank" class="icon_list_white mt10 go-myorder" title="订单"></a>
                <a target="_blank" class="icon_collect_white mt10 go-myhas" title="收藏"></a>
                <a target="_blank" class="icon_history_white mt10 go-record" title="记录"></a>
            </li>
        </ul>
    </div>
    <div class="second">
        <a target="_blank" class="icon_edit_white"></a>
        <a target="_blank" class="icon_top_white mt10"></a>
    </div>
</div>
<script src="../js/config.js"></script>

<script>
    var limit = 10;
    var offset = 1;
    var state ='';
    var _status ='';
    //审核中的权限限制

    get_ajax("/sys/authentication/myAuthentication", {}, function (data) {
        _status = data.state;
    })

    var app = new Vue({
        el: '.store_product',
        data: {
            imgBaseUrl: imgBaseUrl,
            list:"",
            total:'',
            type:localStorage.getItem('type'),
            storeId:localStorage.getItem('storeId')
        },
        beforeCreate: function () {
        },
        mounted:function(){
            this.pagList();

        },
        methods:{
            toEdit:function (id) {
                location.href = "store_prodAdd.html?id="+id
            },
            toUp:function (item) {
                get_ajax("/sys/storeCommodity/grounding", {id:item.id}, function (data) {
                    layer.msg("商品已上架");
                    item.state = 0;
                })
            },
            toDown:function (item) {
                get_ajax("/sys/storeCommodity/del", {id:item.id}, function (data) {
                    layer.msg("商品已下架");
                    item.state = 1;
                })
            },
            pagList:function(){
                get_ajaxPage("/sys/storeCommodity/getMyPage", {limit: limit, offset: offset,state:state}, function (data) {
                    data.data.forEach(function (item) {
                        item.picUrl = item.picUrl.split(",");
                    })
                    app.list = data.data;
                    app.total = data.count;
                    layui.use('laypage', function(){
                        var laypage = layui.laypage;
                        //执行一个laypage实例
                        laypage.render({
                            elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
                            ,count: app.total //数据总数，从服务端得到
                            ,limit:limit
                            ,jump: function(obj, first){
                                //obj包含了当前分页的所有参数，比如：
                                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                                console.log(obj.limit); //得到每页显示的条数
                                //首次不执行
                                if(!first){
                                    get_ajaxPage("/sys/storeCommodity/getMyPage", {limit: limit, offset: obj.curr,state:state}, function (data) {
                                        data.data.forEach(function (item) {
                                            item.picUrl = item.picUrl.split(",");
                                        })
                                        app.list = data.data;
                                        app.total = data.count;
                                    })
                                }
                            }
                        });
                    });
                })
            },
            goProadd:function(){
//                if(_status){
                    window.location.href='store_prodAdd.html';
//                }else if(!_status){
//                    layer.msg('您的店铺还在审核中！')
//                }

            }
        },
        updated: function () {

        }
    })

    $(document).on('click','.js-status',function(){
        $(this).siblings('i').removeClass('active')
        state = $(this).attr('data-status');
        app.pagList();
    })
</script>
</body>
</html>